package com._520it.wms.web.controller;


import com._520it.wms.service.IEmployeeService;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

//登录相关的操作
@Controller
public class LoginController {
    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/login")
    public String login(HttpServletRequest req) {
        String errMsg = "";
        String exceptionClassName = (String) req.getAttribute("shiroLoginFailure");
        //根据shiro返回的异常类路径判断，抛出指定异常信息
        if (exceptionClassName != null) {
            if (UnknownAccountException.class.getName().equals(exceptionClassName)) {
                //最终会抛给异常处理器
                errMsg = "账号不存在";
            } else if (IncorrectCredentialsException.class.getName().equals(
                    exceptionClassName)) {
                errMsg = "用户名/密码错误";
            } else {
                errMsg = "其他异常信息";
            }
        }
        req.setAttribute("errMsg", errMsg);
        return "forward:/login.jsp";

    }

    @RequestMapping("/main")
    public String main() {
        return "main";
    }




}
